from django.db import models

# Create your models here.


class User(models.Model):

    gender = (
        ('male', "男"),
        ('female', "女"),
    )
    departments = (
        ('部门一',"运营部"),
        ('部门二',"销售部"),
        ('部门三',"生产部"),
        ('部门四',"安全部"),
    )
    partyments = (
        ('一支部',"铝合金"),
        ('二支部',"轻量化"),
        ('三支部',"建材"),
        ('四支部',"预算"),
    )
    name = models.CharField(max_length=128, unique=True)
    sex = models.CharField(max_length=32, choices=gender, default="男")
    num = models.CharField(max_length=32,unique=True)  # 工号
    dept = models.CharField(max_length=32, choices=departments, default="运营部")  # 部门
    party = models.CharField(max_length=32, choices=partyments, default="铝合金")  # 党支部
    password = models.CharField(max_length=256)
    email = models.EmailField(unique=True)


    # 注册时间
    c_time = models.DateTimeField(auto_now_add=True)
    # 是否邮件确认
    has_confirmed = models.BooleanField(default=False)

    def __str__(self):
        return self.name

    class Meta:
        ordering = ["-c_time"]
        verbose_name = "用户"
        verbose_name_plural = "用户"


# 邮件的确认码
class ConfirmString(models.Model):
    code = models.CharField(max_length=256)
    user = models.OneToOneField('User', on_delete=models.CASCADE)
    c_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.user.name + ":   " + self.code

    class Meta:

        ordering = ["-c_time"]
        verbose_name = "确认码"
        verbose_name_plural = "确认码"